package a10_动态规划;

import java.util.Arrays;

/**
 * <p>
 * a41_最长递增子序列复习3
 * </p>
 *
 * @author flyduck
 * @since 2025/3/11
 */
public class a41_最长递增子序列复习3 {
    //dp[i]：包含dp[i]的最长递增子序列的长度是dp[i]

    //递推公式：
    //if(nums[i] < nums[j]){
    // dp[i] = Math.max(dp[i],dp[j] + 1);
    //}

    //初始化：dp[0] = 1
    public int lengthOfLIS(int[] nums) {
        int result = 1;

        int[] dp = new int[nums.length];
        Arrays.fill(dp, 1);

        for (int i = 1; i < nums.length; i++) {
            for (int j = 0; j < i; j++) {
                if(nums[i] > nums[j]){
                    dp[i] = Math.max(dp[i],dp[j] + 1);
                }
            }
            result = Math.max(result, dp[i]);
        }

        return result;
    }
}
